package com.chdwmp.product.bean;

import com.chdwmp.product.constant.CommonConstants;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.List;

/**
 * 分页实体
 * @param <T>
 */
@Data
public class PageResult<T> {

    private int totalCount;
    private boolean hasMore;
    private List<T> list;

    public PageResult(int totalCount, boolean hasMore, List<T> list) {
        this.totalCount = totalCount;
        this.hasMore = hasMore;
        this.list = list;
    }

    public PageResult(int totalCount, int startPage, List<T> list) {
        this.totalCount = totalCount;
        this.hasMore = totalCount > (startPage + 1) * CommonConstants.PAGE_SIZE;
        this.list = list;
    }

    public PageResult(int totalCount, int startPage, int rows, List<T> list) {
        this.totalCount = totalCount;
        this.hasMore = totalCount > (startPage + 1) * rows;
        this.list = list;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
}
